<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var x = "aaa"; //全局变量，作用范围为当前文件
      function fn() {
        var y = 123; //局部变量，作用范围只能在该函数
        console.log(x);
      }
      var obj = {
        name: x,
        price: 199.9,
      };
      fn();
      console.log(obj);
      //console.log(y);错误，y为局部变量
    </script>
  </body>
</html>
